# 作者：小七
# 2024年12月31日
class Gun:
    def __init__(self, model):
        self.model = model
        self.bullet_count = 0

    def add_bullet(self, count):
        self.bullet_count += count

    def shoot(self):
        print(f"{self.model}突突突...")
        if self.bullet_count > 0:
            self.bullet_count -= 1
        else:
            print("没有子弹")


class Soldier:
    def __init__(self, name, gun=None):
        self.name = name
        self.gun = gun

    def fire(self):
        if self.gun is None:
            print("[%s] 还没有枪..." % self.name)
            return
        print("冲啊...[%s]" % self.name)
        self.gun.add_bullet(50)
        self.gun.shoot()


if __name__ == '__main__':
    ak47 = Gun("ak47")
    ak47.add_bullet(50)
    ak47.shoot()
    susanduo = Soldier("许三多")
    susanduo.fire()
    susanduo.gun = ak47
    susanduo.fire()

